package com.atguigu01.file.ex2;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class e2 {
    public static void main(String[] args) {
        /*
        Map<Character,Integer> map =new HashMap<>();
        map.put('I',1);
        map.put('V',5);
        map.put('X',10);
        map.put('L',50);
        map.put('C',100);
        map.put('D',500);
        map.put('M',1000);
//        if(map.get('M')>map.get('C')){
//            System.out.println("da");
//        }
        int count = 0,i=0;
        String s="MCMXCIV";
        char[] arr=s.toCharArray();
        if(arr.length==1){
            System.out.println(map.get(arr[0]));
        }else if(arr.length==2){
            if(map.get(arr[0])>=map.get(arr[1])){
                count+=map.get(arr[0])+map.get(arr[1]);
            }else{
                count-=map.get(arr[0])-map.get(arr[1]);
            }
        }else{
            while(i<arr.length-1){
                if(map.get(arr[i])>=map.get(arr[i+1])){
                    count+=map.get(arr[i]);
                }else{
                    count-=map.get(arr[i]);
                }
                i++;
            }

        }
        count+=map.get(arr[arr.length-1]);*/
       // System.out.println(count);
//        for (char c:arr
//             ) {
//            System.out.println(c);
//        }

        System.out.println(isPalindrome("0P"));
    }
    public static boolean isPalindrome(String s) {
        String s1=s.toLowerCase();
        char[] arr1=s1.toCharArray();
        int count=0;
        for (int i = 0; i <arr1.length ; i++) {
            if((arr1[i]>='a'&&arr1[i]<='z')||(arr1[i]>='A'&&arr1[i]<='Z')||(arr1[i]>='0'&&arr1[i]<='9')){
                count++;
            }
        }
        System.out.println(count);

        char[] arr2=new char[count];

        int i=0,j=0;
        while(i< arr1.length&&j<arr2.length){
            if((arr1[i]>='a'&&arr1[i]<='z')||(arr1[i]>='0'&&arr1[i]<='9')){
                arr2[j]=arr1[i];
                i++; j++;
            }else {
                i++;
            }
        }
        for (char c:arr2
             ) {
            System.out.println(c);
        }
        if(arr2.length==0||arr2.length==1){
            return true;
        }
        if((arr2.length==2)&&(arr2[0]!=arr2[1])&&('a'<=arr2[0]&&arr2[0]<='z')&&('a'<=arr2[1]&&arr2[1]<='z')){
            return false;
        }
        if((arr2.length==2)&&(arr2[0]!=arr2[1])&&(('a'<=arr2[0]&&arr2[0]<='z')||('a'<=arr2[1]&&arr2[1]<='z'))){
            return false;
        }
        if(arr2.length==2&&arr2[0]==arr2[1]){
            return true;
        }

        int count2=0;
        for (int k = 0; k < arr2.length/2; k++) {
            if(arr2[k]==arr2[arr2.length-1-k]){
                count2++;
            }
        }
        if (count2==arr2.length/2){
            return true;
        }else{
            return false;
        }

    }

    @Test
    public void t1(){
        int[] nums=new int[]{4,5,6,7,8,9,1,2,3};
        int temp;
        for (int i = 0; i < nums.length; i++) {
            int count=0;
            for (int j = 0; j < nums.length-i-1; j++) {
                if(nums[j]>nums[j+1]){
                    temp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = temp;
                    count = 1;
                }
            }
            if (count==0)
                break;
        }
        for (int i:nums
             ) {
            System.out.println(i);
        }
    }
    @Test
    public void t2(){
        int[] nums=new int[]{1,1,1,2,2,3};
        if(nums.length==0||nums.length==1||nums.length==2){
            System.out.println(nums.length);
        }else{
            int i=0,j=0;
            int count=1;
            int cy;
            int reduce=0;
            int len= nums.length-reduce;
            while(i< len){
                cy=nums[i];
                if(nums[i]==nums[i+1]){
                    if(count<2){
                        count++;
                        i++;
                        j++;
                    }
                    if(count>=2){
                        i++;
                        count++;
                    }
                }else{
                    reduce+=(count-2);
                    int k=i+1;
                    while(k< nums.length){
                        nums[k-(count-2)]=nums[k];
                        k++;
                    }
                }

            }

        }
    }
    @Test
    public void t5(){
        String s="A man, a plan, a canal: Panama";
        String s1=s.toLowerCase();
        char[] arr1=s1.toCharArray();
        int count=0;
        for (int i = 0; i <arr1.length ; i++) {
            if((arr1[i]>='a'&&arr1[i]<'z')||(arr1[i]>='A'&&arr1[i]<'Z')){
                count++;
            }
        }

        char[] arr2=new char[count];
        if(arr2.length==0||arr2.length==1){
            System.out.println("1");
            if(arr2.length==2&&arr2[0]!=arr2[1]){
                System.out.println("0");
        }
            if(arr2.length==2&&arr2[0]==arr2[1]){
                System.out.println("1");
            }
            System.out.println(count);
            int i=0,j=0;
        while(i< arr1.length&&j<arr2.length){
            if(arr1[i]>='a'&&arr1[i]<'z'){
                arr2[j]=arr1[i];
                i++; j++;
            }else {
                i++;
            }
        }

        int count2=0;
        for (int k = 0; k < arr2.length/2; k++) {
            if(arr2[k]==arr2[arr2.length-1-k]){
                count2++;
            }
        }
        if (count2==arr2.length/2){
            System.out.println("1");
        }else{
            System.out.println("0");
        }

    }
}
    }
